import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

let originPush = VueRouter.prototype.push;

VueRouter.prototype.push = function(location,resolve,reject){
	if(resolve && reject){
		originPush.call(this, location, resolve, reject)
	}else{
		originPush.call(this, location, () => {}, () => {})
	}
}

import Home from '@/pages/Home';
import Search from '@/pages/Search';
import Login from '@/pages/Login';
import Register from '@/pages/Register';

export default new VueRouter({
	routes: [
		{
			path: '/home',
			component: Home,
			meta:{show:true}
		},
		{
			path: '/search/:keyWord?',
			component: Search,
			name: 'search',
			meta:{show:true},
			props:(router) => ({keyWord:router.params.keyWord,k:router.query.k})
		},
		{
			path: '/login',
			component: Login,
			meta:{show:false}
		},
		{
			path: '/register',
			component: Register,
			meta:{show:false}
		},
		{
			path: '/',
			redirect: '/home'
		}
	]
})